home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectPlay / Maze / MazeCommon / Maze.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  5.0 KB  |  141 lines

  1. //----------------------------------------------------------------------------
  2. // File: maze.h
  3. //
  4. // Desc: see main.cpp
  5. //
  6. // Copyright (c) 1999-2001 Microsoft Corp. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef _MAZE_H
  9. #define _MAZE_H
  10.  
  11.  
  12.  
  13.  
  14. //-----------------------------------------------------------------------------
  15. // Name: 
  16. // Desc: Client IDs are 32-bit values that refer to a particular Client. They are 
  17. //       broken up into two bitfields, one of which can be used into an index 
  18. //       of a list of Client 'slots', the other bitfield is a "uniqueness" value 
  19. //       that is incremented each time a new Client is created. Hence, although
  20. //       the same slot may be reused by different Clients are different times, 
  21. //       it's possible to distinguish between the two by comparing uniqueness 
  22. //       values (you can just compare the whole 32-bit id).
  23. //-----------------------------------------------------------------------------
  24. typedef DWORD   ClientID;
  25.  
  26. #define PLAYER_OBJECT_SLOT_BITS 13
  27. #define MAX_PLAYER_OBJECTS      (1<<PLAYER_OBJECT_SLOT_BITS)
  28. #define PLAYER_OBJECT_SLOT_MASK (MAX_PLAYER_OBJECTS-1)
  29.  
  30.  
  31.  
  32. //-----------------------------------------------------------------------------
  33. // Name: 
  34. // Desc: 
  35. //-----------------------------------------------------------------------------
  36. #include <assert.h>
  37. #include "Random.h"
  38.  
  39. const   BYTE   MAZE_WALL_NORTH = (1<<0);
  40. const   BYTE   MAZE_WALL_EAST = (1<<1);
  41. const   BYTE   MAZE_WALL_SOUTH = (1<<2);
  42. const   BYTE   MAZE_WALL_WEST = (1<<3);
  43. const   BYTE   MAZE_WALL_ALL = MAZE_WALL_NORTH|MAZE_WALL_EAST|
  44.                                 MAZE_WALL_SOUTH|MAZE_WALL_WEST;
  45.  
  46.  
  47.  
  48.  
  49. //-----------------------------------------------------------------------------
  50. // Name: 
  51. // Desc: 
  52. //-----------------------------------------------------------------------------
  53. struct  MazeCellRef
  54. {
  55.     DWORD   x,y;
  56. };
  57.  
  58.  
  59.  
  60.  
  61. //-----------------------------------------------------------------------------
  62. // Name: 
  63. // Desc: 
  64. //-----------------------------------------------------------------------------
  65. class   CMaze
  66. {
  67. public:
  68.     CMaze();
  69.     ~CMaze();
  70.  
  71.     HRESULT Init( DWORD width , DWORD height , DWORD seed );
  72.     void    Empty();
  73.  
  74.     DWORD   GetWidth()  const { return m_dwWidth; };
  75.     DWORD   GetHeight() const { return m_dwHeight; };
  76.     DWORD   GetSize()   const { return m_dwWidth*m_dwHeight; };
  77.     BYTE   GetCell( DWORD x , DWORD y )    const { assert(m_pMaze!=NULL); return *(m_pMaze+x+(y*m_dwWidth)); };
  78.     BOOL    CanGoNorth( DWORD x , DWORD y ) const { return !(GetCell(x,y)&MAZE_WALL_NORTH); };
  79.     BOOL    CanGoEast( DWORD x , DWORD y )  const { return !(GetCell(x,y)&MAZE_WALL_EAST); };
  80.     BOOL    CanGoSouth( DWORD x , DWORD y ) const { return !(GetCell(x,y)&MAZE_WALL_SOUTH); };
  81.     BOOL    CanGoWest( DWORD x , DWORD y )  const { return !(GetCell(x,y)&MAZE_WALL_WEST); };
  82.  
  83.     // Get list of visible cells from the given position. Fills out the list pointed to
  84.     // be plist, and stops if it blows maxlist. Returns number of visible cells
  85.     DWORD   GetVisibleCells( const D3DXVECTOR2& pos , const D3DXVECTOR2& dir ,
  86.                              float fov , MazeCellRef* plist , DWORD maxlist );
  87.  
  88.     // Get/set max view distance (used by GetVisibleCells)
  89.     DWORD   GetMaxView() const { return m_dwMaxView; };
  90.     void    SetMaxView() { m_dwMaxView = m_dwMaxView; };
  91.  
  92.     BYTE*  m_pMaze;
  93.  
  94. protected:
  95.     DWORD   m_dwWidth;
  96.     DWORD   m_dwHeight;
  97.     DWORD   m_dwSize;
  98.     DWORD   m_dwSeed;
  99.     DWORD   m_dwMaxView;
  100.     CRandom m_Random;
  101.  
  102.     // Local types for the maze generation algorithm
  103.     struct  CellNode
  104.     {
  105.         CellNode*   pPartition;
  106.         CellNode*   pNext;
  107.     };
  108.     struct  WallNode
  109.     {
  110.         DWORD   dwX,dwY;
  111.         DWORD   dwType;
  112.     };
  113.  
  114.     // Local type for visibilty alg state
  115.     struct  VisState
  116.     {
  117.         DWORD           dwPosX,dwPosY;      // Cell containing view position
  118.         D3DXVECTOR2         vPos;               // View position
  119.         D3DXVECTOR2         vDir;               // View direction
  120.         BYTE*          pArray;             // Array in which cell visits are marked
  121.         DWORD           dwMinX,dwMaxX;      // Extents to consider (also array bounds)
  122.         DWORD           dwMinY,dwMaxY;
  123.         DWORD           dwArrayPitch;       // 'Pitch' of array (width)
  124.         MazeCellRef**   ppVisList;          // Pointer to vis list pointer
  125.         DWORD           dwMaxList;          // Maximum length of vis list
  126.         DWORD           dwListLen;          // Current length of vis list
  127.     };
  128.  
  129.     void    RecurseCheckCellVis( VisState& state , DWORD x , DWORD y , D3DXVECTOR2 left , D3DXVECTOR2 right );
  130.     BYTE   ComputeVisFlags( const D3DXVECTOR2& dir , const D3DXVECTOR2& left , const D3DXVECTOR2& right , const D3DXVECTOR2& offset );
  131.  
  132. private:
  133.     CMaze( const CMaze& );
  134.     void operator=( const CMaze& );
  135. };
  136.  
  137.  
  138.  
  139.  
  140. #endif
  141.